<template>
	
	<!-- <div>产品列表{{productlist}}</div> -->
	<flexbox>
	    <flexbox-item>
	     <yd-list theme="1"> 
	          <yd-list-item v-for="item, key in productlist" :key="key"
	          @click.native="productinfo(item)"
	          >
	              <img slot="img" 
	              v-lazy="pic(item.top_pic)"
	              >

	              <span slot="title">{{item.name}}</span>
	              <yd-list-other slot="other">
	                  <div class="mt5">
	                      <span class="red">
	                        <em>¥</em><span class=" h3">{{item.guide_price}}</span>
	                      </span>
	                      <!-- <span class="demo-list-del-price">¥{{item.w_price}}</span> -->
	                  </div>
	                  <div v-if="item.flash_state == '1'">
	                      <yd-countdown
	                        v-if="new Date(item.start_time) > new Date() "
	                       :time="item.start_time"></yd-countdown>

	                      <yd-countdown 
	                        v-if="new Date(item.start_time) <= new Date() "
	                      :time="item.end_time"></yd-countdown>
	                  </div>
	              </yd-list-other>
	          </yd-list-item>
	      </yd-list>
	    </flexbox-item>
	</flexbox>

</template>

<script>

import { mapGetters } from 'vuex';
import { cutImage } from '../../util/util'
	
export default {

	name : 'productlist',

	data () {

		return {


		}

	},


	computed : {

		...mapGetters([
			'company_code',
			'productlist',
			'URL',
		]),
	},

	methods : {
		productinfo (item) {
			console.log(item);
	        console.log('productinfo');

	        var para = {
	        	'company_code' : this.company_code,
	        };

	        if(this.$route.query.u != undefined){
				para['u'] = this.$route.query.u;
			}

			this.$router.push({ 
				name: 'productinfo', 
				params: {
					code: item.code,
				},
				query : para,
			});
		},

		pic (toppic) {
			var result = this.URL.defaultImg;
			if(toppic != undefined){			
				try{
					var ttt = JSON.parse(toppic);
					result = cutImage(ttt[0]);
				}catch(err){
					//console.log(err);
					//result = this.URL.defaultImg;
				}
			}

			return result;
	    },

	},

	mounted () {
		var para = {
			'company_code' : this.company_code,
		};

		if(this.$route.query.type != undefined){
			para['type_code'] = this.$route.query.type;
		}

		if(this.$route.query.name != undefined){
			para['name'] = this.$route.query.name;
		}

		this.$store.dispatch('getProductList', para);

	}

}


</script>

<style scoped>


</style>